<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>History对象实例2</title>
</head>
<body>
<form action="#">
    <input type="text" name="" id="username">
</form>
<button id="btn" onclick="safe()">按钮</button>
<script>
    function safe() {
        var name=document.getElementById("username").value;
        if (name=="hello"){
            history.go(-1);//以自己为中心0 后退是-1 ，前进是+1；
        }else {
            alert("请重新输入用户名");
        }
    }
</script>
</body>
</html>